package com.lbx.redis;

import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisClusterConfiguration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import redis.clients.jedis.JedisCluster;

/**
 * @description:
 * @author: lbx
 * @create: 2018/7/20 18:40
 **/
@Configuration
public class RedisConfig {

    @Autowired
    private RedisProperties redisProperties;

    @Bean
    public JedisCluster getJedisCluster() {
        return new JedisCluster(redisProperties.getClusterNodes(),redisProperties.getTimeOut(),1000,1 ,new GenericObjectPoolConfig());//需要密码连接的创建对象方式
    }

     @Bean
     public RedisConnectionFactory connectionFactory() {
        return new JedisConnectionFactory(
                new RedisClusterConfiguration(redisProperties.getNodes()));
    }


}
